﻿using Digitalmes.Models;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Digitalmes.Signals
{
    public abstract class SignalBase : IRequest<HandleResult>
    {
        public string Sn { get; set; }

        public long LineId { get; set; }

        public string ProductCode { get; set; }


        private ISysTag _tag;
        public ISysTag SignalTag
        {
            get { return _tag; }
            set
            {
                _tag = value;

                if (value.TagGroup != null)
                {
                    var sntag = value.TagGroup.FirstOrDefault(x => x.TagType == Model.TagDefineEnum.Entry_SN ||
                                                           x.TagType == Model.TagDefineEnum.Archive_SN ||
                                                           x.TagType == Model.TagDefineEnum.TakePartIn_SN
                                                         );
                    if (sntag != null)
                    {
                        Sn = sntag.Value?.ToString();
                    }
                    var prodtag = value.TagGroup.FirstOrDefault(x => x.TagType == Model.TagDefineEnum.Archive_Formual ||
                                                        x.TagType == Model.TagDefineEnum.Entry_Formual ||
                                                        x.TagType == Model.TagDefineEnum.ScanBatch_Formual

                                                      );
                    if (prodtag != null)
                    {
                        ProductCode = prodtag.Value?.ToString();
                    }
                }

            }
        }

    }
      
}
